/* 最的问题就是最优解，用动态优化 */
/* 3.无重复的最长子串*/
#include <iostream>
#include <string.h>
#include <string>
using namespace std;

string unrepeatedSubstring(string str) 
{   
    string substring = " ";
    if(str.empty())
    {
        cout << "ERROR" << endl;
        exit(-1);
    }
    
    int len = str.length();

    for(int i = 0; i <= len; i++)
    {
        
        char next = str[i];
        if(substring.find(next) == string::npos)
        {
            substring = substring + next;
        }
        else
        {
            break;
        }   
    }   
    return substring;
}

int main()
{
    while(1)
    {
        string str;
        cout << "请输入字符串：";
        cin >> str;
        cout <<"最长无重复字符串为："  << unrepeatedSubstring(str) << endl;
    }

    return 0;
}